package org.pp.core;

import cn.hutool.core.util.StrUtil;
import java.util.Collection;

public class Assertion {

    /**
     * * 不为空
     *
     * @param obj
     * @param message
     */
    public static void nullThrow(Object obj, String message) {
        if (obj == null) {
            throwMsg(message);
        }
    }

    public static void notNullThrow(Object obj, String message) {
        if (obj != null) {
            throwMsg(message);
        }
    }

    public static void trueThrow(boolean b, String message) {
        if (b) {
            throwMsg(message);
        }
    }

    public static void notTrueThrow(boolean b, String message) {
        if (!b) {
            throwMsg(message);
        }
    }

    public static void equalsThrow(Object o1, Object o2, String message) {
        if (o1 == o2 || (o1 != null && o1.equals(o2))) {
            throwMsg(message);
        }
    }


    public static void emptyThrow(Collection e, String message){
        if(e==null||e.isEmpty()){
            throwMsg(message);
        }
    }

    /**
     * * 抛出信息
     *
     * @param message
     */
    private static void throwMsg(String message) {
        throw BizExcept.erro(message);
    }

    /**
     * * 为空字符串
     *
     * @param str
     * @param message
     */
    public static void blankThrow(String str, String message) {
        if (StrUtil.isBlank(str)) {
            throwMsg(message);
        }
    }

    public static void gtZeroThrow(long num, String message) {
        if (num>0) {
            throwMsg(message);
        }
    }


}
